﻿using System;
using Microsoft.SharePoint;
using System.Collections;

namespace SCCL2010
{
    public static class HelpInformation
    {
        private const string SPQueryFieldName = "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">{0}</Value></Eq></Where>";

        /// <summary>
        /// Gets the details from the Help Information list.
        /// </summary>
        /// <param name="oWeb"></param>
        /// <param name="cFieldName"></param>
        /// <returns>returns a string value representing the Details for a item based on the FieldName.</returns>
        public static string ReadHelpInformation(SPWeb oWeb, String cFieldName)
        {
            return ReadHelpInformation("Help Information", oWeb, cFieldName);
        }

        public static string ReadHelpInformation(string cListName,SPWeb oWeb, String cFieldName)
        {
            try
            {
                var lstConfiguration = oWeb.Lists[cListName];
                SPQuery oQuery = new SPQuery { Query = String.Format(SPQueryFieldName, cFieldName) };
                SPListItemCollection items = lstConfiguration.GetItems(oQuery);

                if (items.Count > 0)
                {
                    SPListItem item = items[0];
                    if (item["Details"] != null)
                        return item["Details"].ToString();
                }
            }
            catch (Exception ex)
            {
                ErrorHandling.HandleError(oWeb, "HelpInformation.ReadHelpInformation", ex);
            }
            return "";
        }




    }
}
